<?php
	$hfbcats 	= getHFBCats();
	$buttons 	= getButtons();
	$buttons	= getButtonsList();
	
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	if($item['id'] > 0)
	{ 
		$item 			= getButtonAdmin($item['id']); 
		$incats 		= getInHFBCats($item['id'], 3);
	}
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{ addButton($_POST['name']); }
			$i=0;
			if($_POST['btn_id'])
			{
				foreach($_POST['btn_id'] as $id)
				{
					updateButton($id, $_POST['btn_name'][$i], $_POST['btn_height'][$i], $_POST['btn_type'][$i]);
					$i++;
				}
			}
			if($_POST['load_css'] > 0)
			{ reloadHFBTypeCss($_POST['load_css']); }
			if($_POST['activate'] > 0)
			{ setTableActive($_POST['activate'], 'buttons', 1); }
			if($_POST['deactivate'] > 0)
			{ setTableActive($_POST['deactivate'], 'buttons', 0); }
			if($_POST['delete_button'] > 0)
			{ deleteButton($_POST['delete_button']); } 
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				updateButton($item['id'], $_POST['name'], $_POST['height'], $_POST['type']);
				uploadButtonImages($item['id']);
				if(($_POST['delete_l'] == "1") && ($item['l_image'] != ""))
				{ deleteButtonImage($item['id'], 'l_image', $item['l_image']); }
				if(($_POST['delete_l_h'] == "1") && ($item['l_image_h'] != ""))
				{ deleteButtonImage($item['id'], 'l_image_h', $item['l_image_h']); }
				
				if(($_POST['delete_r'] == "1") && ($item['r_image'] != ""))
				{ deleteButtonImage($item['id'], 'r_image', $item['r_image']); }
				if(($_POST['delete_r_h'] == "1") && ($item['r_image_h'] != ""))
				{ deleteButtonImage($item['id'], 'r_image_h', $item['r_image_h']); }
				
				if(($_POST['delete_bg'] == "1") && ($item['image'] != ""))
				{ deleteButtonImage($item['id'], 'image', $item['image']); }
				if(($_POST['delete_bg_h'] == "1") && ($item['image_h'] != ""))
				{ deleteButtonImage($item['id'], 'image_h', $item['image_h']); }
				
				if($_POST['add_to_cat'] > 0)
				{ addItemToCat($item['id'], 3, $_POST['add_to_cat']);}
				if($_POST['rem_from_cat'] > 0)
				{ removeItemFromCat($item['id'], 3, $_POST['rem_from_cat']);}
				
				if($_POST['cb_div'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'], trim($_POST['cb_div'])); }
				
				if($_POST['cb_a'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a', trim($_POST['cb_a'])); }
				
				if($_POST['cb_button'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' button', trim($_POST['cb_button'])); }
				if($_POST['cb_button_hover'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' button:hover, div.com_buttons div.cb_'.$item['id'].' button.active', trim($_POST['cb_button_hover'])); }
				if($_POST['cb_button_txt'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' button span', trim($_POST['cb_button_txt'])); }
				
				if($_POST['ui-button'])
				{ updateCss(3,$item['id'],'.cb_'.$item['id'].' .ui-button', trim($_POST['ui-button'])); }
				if($_POST['ui-button-text'])
				{ updateCss(3,$item['id'],'.cb_'.$item['id'].' .ui-button-text', trim($_POST['ui-button-text'])); }
				
				if($_POST['cb_a_h'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a:hover', trim($_POST['cb_a_h'])); }
				if($_POST['cb_a_active'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a.active', trim($_POST['cb_a_active'])); }
				
				if($_POST['cb_span_right'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a span.right', trim($_POST['cb_span_right'])); }
				if($_POST['cb_span_right_h'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a:hover span.right', trim($_POST['cb_span_right_h'])); }
				if($_POST['cb_span_right_active'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a.active span.right', trim($_POST['cb_span_right_active'])); }
				
				if($_POST['cb_span'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a span.right span', trim($_POST['cb_span'])); }
				if($_POST['cb_span_h'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a:hover span.right span', trim($_POST['cb_span_h'])); }
				if($_POST['cb_span_active'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a.active span.right span', trim($_POST['cb_span_active'])); }
				
				if($_POST['cb_span_span_center'])
				{ updateCss(3,$item['id'],'div.com_buttons div.cb_'.$item['id'].' ul li.com_button a span.right span span.center', trim($_POST['cb_span_span_center'])); }
				reloadHFBTypeCss(3);
			}
			break;
	}
	if($_REQUEST['cat'] > 0)
	{ $buttons = getButtons($_REQUEST['cat']); }
	else
	{ $buttons = getButtons(); }
	if($item['id'] > 0)
	{ 
		$item = getButtonAdmin($item['id']); 
		$incats = getInHFBCats($item['id'], 3);
	}
?>